//
//  BookingController.m
//  NZTaxi
//
//  Created by Allan Vergara on 17/09/10.
//  Copyright 2010 List-it. All rights reserved.
//

#import "BookingController.h"
#import "PickupTVC.h"
#import "TaxiTypeTVC.h"
#import "TravelDateTVC.h"
#import "TextFieldTVC.h"
#import "TaxiCompany.h"
#import "AddressSelectorType.h"
#import "Region.h"
#import "CitySelector.h"
#import "JSON/JSON.h"
#import "TaxiCompanyController.h"
#import "MyManager.h"
#import "TaxiCompanyView.h"

@interface BookingController(Private)
-(void)showBookItButton;
-(void)handleError:(NSError *)error;
-(void)hideActivityIndicator;
-(void)showActivityIndicator;
@end

@implementation BookingController

@synthesize destinationAddress, pickupAddress, tempDateSelection, responseData, instructionCell;


// section index
uint const C_ADDRESS_SECTION      = 0;
uint const C_TAXI_TYPE_SECTION    = 1;
uint const C_SPECIAL_INST_SECTION = 2;

// row index
uint const C_PICKUP_ADDRESS      = 0;
uint const C_DESTINATION_ADDRESS = 1;

NSString * const C_TAXI_VEHICLE_TYPE     = @"TAXI_VEHICLE_TYPE";
NSString * const C_TAXI_COMPANY_TYPE     = @"TAXI_COMPANY_TYPE";
NSString * const C_NOTIFY_ADDRESS_CHANGE = @"Notify_Address_change";
NSString * const C_TAXI_COY_TITLE        = @"Taxi Company";
NSString * const C_TAXI_TYPE_TITLE       = @"Taxi Type";

// Vehicle Types
NSString * const C_SEDAN       = @"Four seat sedan";
NSString * const C_WAGON       = @"Station Wagon";
NSString * const C_SEVEN       = @"7 Seater";
NSString * const C_TEN         = @"10 Seater";
NSString * const C_BUSINESS    = @"Business class";
NSString * const C_CAR_SEAT    = @"Car Seat";
NSString * const C_WHEEL_CHAIR = @"Wheelchair";

UIDatePicker *datePicker;

#pragma mark -
#pragma mark helper methods


-(void)ResetFields 
{
	/*self.pickupAddress.city = @"";
     self.pickupAddress.street = @"";
     self.pickupAddress.suburb = @"";
     self.pickupAddress.houseNumber = @"";*/
	
	NSDateFormatter *df = [[NSDateFormatter alloc] init];
	[df setDateStyle:NSDateFormatterLongStyle];
	[df setTimeStyle:NSDateFormatterMediumStyle];
	self.tempDateSelection = [NSString stringWithFormat:@"%@", [df stringFromDate: [NSDate date]]];
	[df release];						 
	
	/*self.destinationAddress.city = @"";
     self.destinationAddress.street = @"";
     self.destinationAddress.suburb = @"";
     self.destinationAddress.houseNumber = @"";*/
}

-(IBAction)btnDoneClick:(id)sender {
	[self btnBookItClicked];	
}

-(void)btnBookItClicked {	
    UIViewController *controller = [[CitySelector alloc] initWithNibName:@"TaxiSelectorView" bundle:nil];
    
    [self.navigationController pushViewController:controller animated:YES];
    [controller release];
}


-(UIImage *)getSelectedImage:(NSString *)imageSource;
{
    NSString * result;
    
    if (imageSource == C_SEDAN)
        result = [[NSBundle mainBundle] pathForResource:@"67x67_sedan1" ofType:@"png"];
    else if (imageSource == C_WAGON)
        result = [[NSBundle mainBundle] pathForResource:@"67x67_5door1" ofType:@"png"];
    else if (imageSource == C_SEVEN)
        result = [[NSBundle mainBundle] pathForResource:@"67x67_minivan1" ofType:@"png"];
    else if (imageSource == C_TEN)
        result = [[NSBundle mainBundle] pathForResource:@"67x67_14seat1" ofType:@"png"];
    else if (imageSource == C_BUSINESS)
        result = [[NSBundle mainBundle] pathForResource:@"67x67_sedan" ofType:@"png"];
    else if (imageSource == C_CAR_SEAT)
        result = [[NSBundle mainBundle] pathForResource:@"67x67_baby" ofType:@"png"];
    else 
        result = [[NSBundle mainBundle] pathForResource:@"67x67_disabled" ofType:@"png"];
    
    return [UIImage imageWithContentsOfFile:result];
}

#pragma mark -
#pragma mark View lifecycle

- (void)viewWillAppear:(BOOL)animated {
	MyManager *sharedManager = [MyManager sharedMyManager];
	if ([sharedManager isCustomerRegistered] == YES) {		
		[self showBookItButton];
	}
    
    if ([sharedManager.customerPickupAddress length] > 0) {
        self.pickupAddress = sharedManager.customerPickupAddressObj;
    }
    
    if ([sharedManager.customerDestinationAddress length] > 0) {
        self.destinationAddress = sharedManager.customerDestinationAddressObj;
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
	/*
     UIBarButtonItem *btnDone = [[UIBarButtonItem alloc] init];		
     btnDone.title = @"Book it!";		
     btnDone.target = self;		
     btnDone.action = @selector(btnDoneClick:);		
     self.navigationItem.rightBarButtonItem = btnDone;
     */
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
	/*NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"PickupTVC" owner:self options:nil];
     pickupCell = (PickupTVC *)[topLevelObjects objectAtIndex:0];
     pickupCell.Caption.text = @"Pickup address:";
     pickupCell.Address.text = @"select address";
     
     topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"PickupTVC" owner:self options:nil];
     destinationCell = (PickupTVC *)[topLevelObjects objectAtIndex:0];
     destinationCell.Caption.text = @"Destination address:";
     destinationCell.Address.text = @"select address";
     
     travelDateCell = [[TravelDateTVC alloc] init];
     taxiShareCell = [[TravelDateTVC alloc] init];
     taxiCoyCell = [[TaxiCoyTVC alloc] init];*/
	
	//TaxiCompany *arrayObj;
	vehicleTypes = [[NSMutableArray alloc] initWithCapacity:6];
    
    [vehicleTypes addObject: C_SEDAN];
    [vehicleTypes addObject: C_WAGON];
    [vehicleTypes addObject: C_SEVEN];
    [vehicleTypes addObject: C_TEN];
    [vehicleTypes addObject: C_BUSINESS];
    [vehicleTypes addObject: C_CAR_SEAT];
    [vehicleTypes addObject: C_WHEEL_CHAIR];
    
    
    /*taxiCompanies = [[NSMutableArray alloc] initWithCapacity:6];
     NSString *imgSource;
     
     TaxiCompanyView *view = [[TaxiCompanyView alloc] initWithFrame:CGRectZero];
     imgSource = [[NSBundle mainBundle] pathForResource:@"clover" ofType:@"png"];
     view.image = [UIImage imageWithContentsOfFile:imgSource];    
     view.title = @"Clover Taxi";
     [taxiCompanies addObject:view];
     [view release];
     
     view = [[TaxiCompanyView alloc] initWithFrame:CGRectZero];
     imgSource = [[NSBundle mainBundle] pathForResource:@"diamond" ofType:@"png"];
     view.image = [UIImage imageWithContentsOfFile:imgSource];   
     view.title = @"Diamond Cabs";
     [taxiCompanies addObject:view];
     [view release];
     
     view = [[TaxiCompanyView alloc] initWithFrame:CGRectZero];
     imgSource = [[NSBundle mainBundle] pathForResource:@"spade" ofType:@"png"];
     view.image = [UIImage imageWithContentsOfFile:imgSource];   
     view.title = @"Aces of Spades";
     [taxiCompanies addObject:view];
     [view release];
     
     view = [[TaxiCompanyView alloc] initWithFrame:CGRectZero];
     imgSource = [[NSBundle mainBundle] pathForResource:@"ruby" ofType:@"png"];
     view.image = [UIImage imageWithContentsOfFile:imgSource];  
     view.title = @"Ruby Transport";
     [taxiCompanies addObject:view];
     [view release];
     
     view = [[TaxiCompanyView alloc] initWithFrame:CGRectZero];
     imgSource = [[NSBundle mainBundle] pathForResource:@"hearts" ofType:@"png"];
     view.image = [UIImage imageWithContentsOfFile:imgSource];   
     view.title = @"Hearts Taxis";
     [taxiCompanies addObject:view];
     [view release];
     
     view = [[TaxiCompanyView alloc] initWithFrame:CGRectZero];
     imgSource = [[NSBundle mainBundle] pathForResource:@"school_board" ofType:@"png"];
     view.image = [UIImage imageWithContentsOfFile:imgSource];  
     view.title = @"School Cabs";
     [taxiCompanies addObject:view];*/
	
	if (responseData == nil) {
		responseData = [[NSMutableData alloc] init];
	}
	
	[self ResetFields];
    
    // pre set address object
	NSUserDefaults *preps = [NSUserDefaults standardUserDefaults];
	
	selectedVehicle = [preps objectForKey: C_TAXI_VEHICLE_TYPE];

	
	NSString *s = @"";
	
	[preps setObject:s forKey:C_SELECTED_CITY];
	
	pickupAddress = [[Address alloc] init];
	if ([s length] != 0) {
		[self.pickupAddress setCity:s];
    }
	
	destinationAddress = [[Address alloc] init];
	[preps setObject:destinationAddress.city forKey:C_SELECTED_CITY];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
	self.navigationItem.title = @"Booking";
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section) {
        case C_ADDRESS_SECTION:
            return 65;
            
        case C_TAXI_TYPE_SECTION:
            return 75;
            
        case C_SPECIAL_INST_SECTION:
            return 100;
            
        default:
            return 65;
    }
}

- (void)AddressChanged:(NSNotification *)notification {
	//[self.navigationController popViewControllerAnimated:YES];
	[self.navigationController popToViewController:self animated:YES];
	
	// unregister for notification
	[[NSNotificationCenter defaultCenter] removeObserver:self];
    
	Address *address = [notification object];
	MyManager *sharedManager = [MyManager sharedMyManager];
	
	if (address != NULL) 
	{
		NSString *customerAddress = [[NSString alloc] initWithFormat:@"%@ %@, %@, %@", 
									 address.houseNumber,
									 address.street, 
									 address.suburb,
									 address.city];
		
		if (selectedAddressType == atPickup) {
			self.pickupAddress = address;
            sharedManager.customerPickupAddressObj = address;
			sharedManager.customerPickupAddress = customerAddress;
		} else {			
			self.destinationAddress = address;
            sharedManager.customerDestinationAddressObj = address;
			sharedManager.customerDestinationAddress = customerAddress;
		}
		
        [customerAddress release];
        
		// set home address if applicable
		if (address.isHomeAddress)
		{
			NSUserDefaults *preps = [NSUserDefaults standardUserDefaults];
			
			[preps setValue:[address houseNumber] forKey:C_HOME_HOUSE_NUMBER];
			[preps setValue:[address street] forKey:C_HOME_STREET];
			[preps setValue:[address suburb] forKey:C_HOME_SUBURB];
			[preps setValue:[address city] forKey:C_HOME_CITY];
		}
		
		[self.tableView reloadData];
	}
}

#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    // Return the number of rows in the section.
    switch (section) {
        case C_ADDRESS_SECTION:
            return 2;
        case C_TAXI_TYPE_SECTION:
            return 1;
        default:
            return 1;
    }
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
	NSString *CellIdentifier;
	UITableViewCell *cell;
	
	if (indexPath.section == C_ADDRESS_SECTION) {
        CellIdentifier = @"PickupCell";
	} 
    else if (indexPath.section == C_TAXI_TYPE_SECTION) {
		CellIdentifier = @"TaxiCoy";
    }	 
    else {
        CellIdentifier = @"SpecialInstructions";
    }
    
	cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
	
    if (cell == nil) {
		NSString *nibName;
		
		if (indexPath.section == C_ADDRESS_SECTION) {
			nibName = @"PickupTVC";
		} 
        else if (indexPath.section == C_TAXI_TYPE_SECTION) {
            nibName = @"TaxiTypeTVC";
        }
        else {
            nibName = @"TextFieldTVC";
        }
		
		NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:nil];
		
		// Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
		cell = [topLevelObjects objectAtIndex:0];
	}
    
    // Configure the cell...
	if (indexPath.section == C_ADDRESS_SECTION) {
		if (indexPath.row == C_PICKUP_ADDRESS) {
			((PickupTVC *)cell).Caption.text = @"Pickup:";
			
			if ([pickupAddress.city length] > 0) {
				((PickupTVC *)cell).Address.text = [NSString stringWithFormat:@"%@ %@, %@, %@", pickupAddress.houseNumber,
                                                    pickupAddress.street, pickupAddress.suburb,
                                                    pickupAddress.city];
			}
            
		}
		else {
			((PickupTVC *)cell).Caption.text = @"Destination:";
			
			if ([destinationAddress.city length] > 0) {
				((PickupTVC *)cell).Address.text = [NSString stringWithFormat:@"%@ %@, %@, %@", destinationAddress.houseNumber,
                                                    destinationAddress.street, destinationAddress.suburb,
                                                    destinationAddress.city];
			}
		}
	} 
    else if (indexPath.section == C_TAXI_TYPE_SECTION) {
        ((TaxiTypeTVC *)cell).taxiTypeLabel.text = selectedVehicle; 
        ((TaxiTypeTVC *)cell).taxiTypeImage.image = [self getSelectedImage: selectedVehicle];
	}
    else {
        
        MyManager *mgr = [MyManager sharedMyManager];
        instructionCell = ((TextFieldTVC *)cell);
        instructionCell.TextField.delegate = self;
        instructionCell.TextField.text = mgr.specialInstructions;
        
        ((TextFieldTVC *)cell).Caption.text = @"Special Instructions:";
    }
	
    return cell;
}

#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{	
	if (indexPath.section == C_ADDRESS_SECTION) 
    {
		AddressSelectorType *controller = [[AddressSelectorType alloc] initWithNibName:@"AddressSelectorType" bundle:nil];
		
		// register for notification
		[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(AddressChanged:)
													 name:C_NOTIFY_ADDRESS_CHANGE object:nil];
		
		if (indexPath.row == C_PICKUP_ADDRESS)
			selectedAddressType = atPickup;
		else {
			selectedAddressType = atDropoff;
		}
        
		// Pass the selected object to the new view controller.
		[self.navigationController pushViewController:controller animated:YES];
		[controller release];
	}
    else if (indexPath.section == C_TAXI_TYPE_SECTION) {
        [self showTaxiTypePicker];
    }
}

#pragma mark -
#pragma mark Action sheet delegate

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
	NSLog(@"%d", buttonIndex);
    
	if (actionSheet.title == C_TAXI_TYPE_TITLE) {
		NSUserDefaults *preps = [NSUserDefaults standardUserDefaults];
		[preps setObject:selectedVehicle forKey:C_TAXI_VEHICLE_TYPE];
		
		NSIndexPath *myIndexPath = [NSIndexPath indexPathForRow:0 inSection:C_TAXI_TYPE_SECTION];
		UITableViewCell *cell = [[self tableView] cellForRowAtIndexPath:myIndexPath];
		if(cell == nil) {
			NSLog(@"Cell is nil"); // Cell is always nil
		} else {
			((TaxiTypeTVC *)cell).taxiTypeLabel.text = selectedVehicle;
		}
	}
}	

#pragma mark - 
#pragma mark Picker view delegate
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
	NSLog(@"%d", row);
   
    selectedVehicle = [vehicleTypes objectAtIndex:row];
        
    NSIndexPath *myIndexPath = [NSIndexPath indexPathForRow:0 inSection:C_TAXI_TYPE_SECTION];
    UITableViewCell *cell = [[self tableView] cellForRowAtIndexPath:myIndexPath];
    if(cell == nil) {
        NSLog(@"Cell is nil"); // Cell is always nil
    } else {
        ((TaxiTypeTVC *)cell).taxiTypeLabel.text = selectedVehicle;
        ((TaxiTypeTVC *)cell).taxiTypeImage.image = [self getSelectedImage:selectedVehicle];
    }
}

#pragma mark -
#pragma mark TextField delegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{    
    [textField resignFirstResponder];
    
    return YES;
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
}

#pragma mark - 
#pragma mark Picker view datasource
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    return ((NSString *)[vehicleTypes objectAtIndex:row]);
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
	return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    //if (pickerView == taxiPicker)
    return [vehicleTypes count];
    //else 
    //    return [taxiCompanies count];
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row 
          forComponent:(NSInteger)component reusingView:(UIView *)view 
{
    //if (pickerView == companyPicker)
    //    return[taxiCompanies objectAtIndex:row];
    //else {
    UILabel *pickerRowLabel = (UILabel *)view;
    if (pickerRowLabel == nil) {
        CGRect frame = CGRectMake(10.0, 0.0, 270, 44);
        pickerRowLabel = [[[UILabel alloc] initWithFrame:frame] autorelease];
        pickerRowLabel.backgroundColor = [UIColor clearColor];
        pickerRowLabel.userInteractionEnabled = YES;
    }
    
    pickerRowLabel.text = [vehicleTypes objectAtIndex:row];
    
    return pickerRowLabel;
    //}
}

#pragma mark -
#pragma mark Class methods
-(void)showTaxiCoyPicker {
	/*UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:C_TAXI_COY_TITLE delegate:self cancelButtonTitle:@"OK"
     destructiveButtonTitle:nil otherButtonTitles:nil];
     companyPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 100,0,0)];	
     companyPicker.delegate = self;
     companyPicker.showsSelectionIndicator = YES;
     
     [action addSubview:companyPicker];
     [action showInView:self.view];
     [action setBounds:CGRectMake(0,0,320,600)];
     [companyPicker release];
     [action release];*/
}

-(void)showTaxiTypePicker {
	UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:C_TAXI_TYPE_TITLE delegate:self cancelButtonTitle:@"OK"
										  destructiveButtonTitle:nil otherButtonTitles:nil];
	
	
	taxiPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 100,0,0)];	
	taxiPicker.delegate = self;
	taxiPicker.showsSelectionIndicator = YES;
	
	[action addSubview:taxiPicker];
	[action showInView:self.view];
	[action setBounds:CGRectMake(0,0,320,600)];
	[taxiPicker release];
	[action release];
}

#pragma mark -
#pragma mark Sockets

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
	[responseData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {	    
    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
    
    // http code within 200 range is ok
    if ((([httpResponse statusCode]/100) == 2)) {
        [responseData setLength:0];
        
        // inform customer that their job requires has been dispatched
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Booking sent successfully" 
                                                            message:@"Your taxi booking has been dispatched. You will get a text message once your request has been received by a designated taxi." 
                                                           delegate:nil 
                                                  cancelButtonTitle:@"OK" 
                                                  otherButtonTitles:nil];
        
        [alertView show];
        [alertView release];
        [self.navigationController popViewControllerAnimated:TRUE];
        
    } else {
        NSDictionary *userInfo = [NSDictionary dictionaryWithObject:@"Problem encountered while connecting to the server. Please try again."
                                                             forKey:NSLocalizedDescriptionKey];
        NSError *error = [NSError errorWithDomain:@"HTTP" code:[httpResponse statusCode] userInfo:userInfo];
		[self hideActivityIndicator];
        [self handleError:error];
    }		
    
    [self showBookItButton];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
	if ([error code] == kCFURLErrorNotConnectedToInternet){
		NSDictionary *userInfo = [NSDictionary dictionaryWithObject:@"You have a problem with your internet connection. Please try again." 
															 forKey:NSLocalizedDescriptionKey ];
		
        NSError *noConnectionError = [NSError errorWithDomain:NSCocoaErrorDomain
                                                         code:kCFURLErrorNotConnectedToInternet
                                                     userInfo:userInfo];
		[self handleError:noConnectionError];
	} else {
		[self handleError:error];
	}
	
	[self showBookItButton];
}

/*
 *	Expected JSON reply format : 
 *		{ "d" : { "RequestJob" : { "status":200, "message":"OK" } } }
 *
 *	TODO: check for empty status
 */
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {		
	NSString *jsonStr = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
	
	// assign the new string to a static string so we can release jsonString
	NSString *cleanStr = [jsonStr stringByReplacingOccurrencesOfString:@"\\" withString:@""];
	cleanStr = [cleanStr stringByReplacingOccurrencesOfString:@"\"{" withString:@"{"];
	cleanStr = [cleanStr stringByReplacingOccurrencesOfString:@"}\"" withString:@"}"];
	
	NSDictionary *dictionary = [cleanStr JSONValue];
	NSDictionary *cleanDictionary = (NSDictionary *)[dictionary objectForKey:@"d"];
	
	NSDictionary *result = (NSDictionary *)[cleanDictionary objectForKey:@"RequestJob"];
	
	NSInteger status = [[result objectForKey:@"status"] integerValue];
	
	switch (status) {
		case 500:
			// TODO: issue error message
			break;
		case 200:
			// TODO: populate history
			[self showBookItButton];			
			break;
		default:
			break;
	}
    
    responseData = nil;
	[responseData release];
    [jsonStr release];
}

#pragma mark -
#pragma mark buttons
-(void)showBookItButton {
	UIBarButtonItem *btnDone = [[UIBarButtonItem alloc] init];
	
	btnDone.title = @"Book it!";
	btnDone.target = self;
	btnDone.action = @selector(btnDoneClick:);
	
	self.navigationItem.rightBarButtonItem = btnDone;
    [btnDone release];
}

#pragma mark -
#pragma mark Error/Message Handler

- (void)handleError:(NSError *)error {
	NSString *errorMessage = [error localizedDescription];
	UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:errorMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
	
	[alertView show];
	[alertView release];
}

#pragma mark -
#pragma mark Activity Indicator
-(void)showActivityIndicator {
	UIActivityIndicatorView *activityIndicatorRightBarItem = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
	[activityIndicatorRightBarItem startAnimating];
	UIBarButtonItem *activityItem = [[UIBarButtonItem alloc] initWithCustomView:activityIndicatorRightBarItem];
	[activityIndicatorRightBarItem release];
	self.navigationItem.rightBarButtonItem = activityItem;	
    [activityItem release];
}

-(void)hideActivityIndicator {
	self.navigationItem.rightBarButtonItem = nil;
}

#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Relinquish ownership any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;
}

- (void)dealloc {	
	[tempDateSelection release];
	[pickupAddress release];
	[destinationAddress release];
    [vehicleTypes release];
    //[taxiCompanies release];
    
    [super dealloc];
}

@end

